﻿<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>DOM动态删除元素</title>
<script>
function del(){
var txt=document.getElementById("txt").value;
var list=document.getElementById("list");
var ops=list.getElementsByTagName("option");
for(var i=0;i<ops.length;i++){
if(ops[i].innerHTML==txt){
list.removeChild(ops[i]);
break;
}
if(i==ops.length){
alert("要删除的水果不存在！");
}
}
//在此编写代码

}
</script>
</head>
<body>
<input type="text" id="txt">
<input type="button" id="btn1" value="删除" onClick="del();">
<select id="list">
<option>苹果</option>
<option>香蕉</option>
<option>梨</option>
</select>
</body>
</html>